﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;


namespace CIB.AutoTitle.ServerCode
{
    public static class Core
    {
        public static string FieldMaskSuffix = "CIB.Mask";
        public static string DateFormatMaskSuffix = "CIB.DateFormat";

        public static string CIBGetProperty(this SPFolder SPObject, string PropertyName)
        {
            return (string)SPObject.GetProperty(PropertyName);
        }

        public static void CIBSetProperty(this SPFolder SPObject, string PropertyName, object PropertyValue)
        {
           SPObject.SetProperty(PropertyName, PropertyValue);
           SPObject.Update();
        }

        public static Dictionary<string,string> CIBFilterProperties(this SPFolder SPObjects, string Filter)
        {
            var Fields = SPObjects.Properties
                .Cast<DictionaryEntry>()
                .Where(prop => prop.Key.ToString().IndexOf(Filter, System.StringComparison.Ordinal) != -1)
                .ToDictionary(
                    prop => prop.Key.ToString(), 
                    prop => prop.Value.ToString());
            return Fields;
        }



    }
}
